#pragma once
#include<iostream>
#include<assert.h>
using namespace std;

namespace Lh
{
	class string
	{

		static const size_t npos;

		using iterator = char*;
		using const_iterator = const char*;
	public:
		//string();
		string(const char* str = " ");
		string(const string& s);
		//string& operator=(const string& s);
		string& operator=(string s);
		~string();

		const char* c_str() const
		{
			return _str;
		}

		iterator begin()
		{
			return _str;
		}

		iterator end()
		{
			return _str + _size;
		}

		const_iterator begin() const
		{
			return _str;
		}

		const_iterator end() const
		{
			return _str + _size;
		}
		size_t size() const
		{
			return _size;
		}
		size_t capacity() const
		{
			return _capacity;
		}

		char& operator[](size_t pos)
		{
			return _str[pos];
		}

		const char& operator[](size_t pos) const
		{
			return _str[pos];
		}
		void clear()
		{
			_str[0] = '\0';
			_size = 0;
		}

		void swap(string& s);

		void reserve(size_t n);

		void push_back(char ch);
		void append(const char* str);
		string& operator+=(char ch);
		string& operator+=(const char* str);

		void insert(size_t pos, char ch);
		void insert(size_t pos, const char* str);
		void erase(size_t pos, size_t len = npos);

		size_t find(char ch, size_t pos = 0);
		size_t find(const char* str, size_t pos = 0);

		string substr(size_t pos, size_t len = npos);

	private:
		char* _str = nullptr;
		size_t _size = 0;
		size_t _capacity = 0;
	};

	void swap(string& s1, string& s2);

	bool operator==(const string& lstr, const string& rstr);
	bool operator<=(const string& lstr, const string& rstr);
	bool operator>=(const string& lstr, const string& rstr);
	bool operator<(const string& lstr, const string& rstr);
	bool operator>(const string& lstr, const string& rstr);
	bool operator!=(const string& lstr, const string& rstr);

	ostream& operator<<(ostream& os, const string& str);
	istream& operator>>(istream& is, string& str);

	istream& getline(istream& is, string& str, char delim = '\0');

};

